﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using SMS.Common.DataAccess;
using System.Linq.Expressions;

namespace SMS.Common.Search
{
    /// <summary>
    /// 字符串筛选条件
    /// </summary>
    [Serializable]
    [DataContract()]
    public class StringFilterCondition : ExpressSearchCondition
    {
        public StringFilterCondition()
        {
        }

        public StringFilterCondition(string filter)
        {
            this.Filter = filter;
            this.LoadAllRecords = true;
        }

        /// <summary>
        /// 筛选条件
        /// </summary>
        [DataMember]
        public string Filter { get; set; }


        /// <summary>
        /// 获取筛选条件所表示的表达式
        /// </summary>
        /// <typeparam name="T">表达式上下文实体类型</typeparam>
        /// <returns>返回Linq To SQL的条件筛选表达式</returns>
        public override Expression<Func<T, bool>> GetExpress<T>()
        {
            if (!string.IsNullOrEmpty(this.Filter))
            {
                return DynamicExpression.ParseLambda<T, bool>(this.Filter, null);
            }
            else
            {
                return null;
            }

        }
    }
}
